
using System.ComponentModel.DataAnnotations;  // 用于 [Required] 和 [Range] 特性
using System.Net;                          // 用于 IPAddress 和 IPEndPoint
namespace RevitCopilot.Config.Options;

public class SocketSettings
{
    public const string SectionName = "SocketSettings";
    
    [Required(ErrorMessage = "IP地址不能为空")]
    public string IpAddress { get; set; } = "0.0.0.0";
    
    [Range(1, 65535, ErrorMessage = "端口必须在1-65535之间")]
    public int Port { get; set; } = 8080;
    
    [Range(1, 1000, ErrorMessage = "Backlog必须在1-1000之间")]
    public int Backlog { get; set; } = 100;
    
    [Range(1, 300, ErrorMessage = "超时时间必须在1-300秒之间")]
    public int ReceiveTimeout { get; set; } = 30; // 秒
    
    [Range(1, 300, ErrorMessage = "超时时间必须在1-300秒之间")]
    public int SendTimeout { get; set; } = 30; // 秒
    
    // 实用方法：获取终结点
    public IPEndPoint GetEndPoint() => new(IPAddress.Parse(IpAddress), Port);
    
    // 实用方法：获取超时时间(毫秒)
    public int ReceiveTimeoutMs => ReceiveTimeout * 1000;
    public int SendTimeoutMs => SendTimeout * 1000;
}